package ua.kpi_java_training.zabrodskyi.module3;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author Maksym Zabrodskyi
 * @version 22-Jun-2013
 */
public class CellTest {

	Cell cell;
	Cell newCell;

	@Test
	public void shouldCreateCell() {
		cell = new Cell();
		assertNotNull(cell);
	}

	@Test
	public void shouldCreateCellWithCoordinatsXY() {
		cell = new Cell(5, 5);
		assertNotNull(cell);
	}

	@Test
	public void shouldCreateNewCellFromCell() {
		cell = new Cell(1, 1);
		newCell = new Cell(cell);
		assertNotNull(newCell);
		assertEquals(cell, newCell);
	}

	@Test
	public void shouldSetNewCellFromCell() {
		cell = new Cell(2, 2);
		newCell = new Cell(1, 1);
		newCell.setCell(cell);
		assertEquals(cell, newCell);
	}

	@Test
	public void fromCellShouldGetX() {
		cell = new Cell(2, 1);
		int x = cell.getX();
		assertEquals(x, 2);
	}

	@Test
	public void inCellShouldSetX() {
		cell = new Cell(3, 1);
		newCell = new Cell(2, 1);
		newCell.setX(3);
		assertEquals(cell, newCell);
	}

	@Test
	public void fromCellShouldGetY() {
		cell = new Cell(1, 2);
		int y = cell.getY();
		assertEquals(y, 2);
	}

	@Test
	public void inCellShouldSetY() {
		cell = new Cell(2, 4);
		newCell = new Cell(2, 1);
		newCell.setY(4);
		assertEquals(cell, newCell);
	}

	@Test
	public void shouldIsBadCellBecauseNegatineX() {
		cell = new Cell(-1, 2);
		assertTrue(cell.isBad());
	}

	@Test
	public void shouldIsBadCellBecauseXBiggerWidthEnvironment() {
		cell = new Cell(15, 1);
		assertTrue(cell.isBad());
	}

	@Test
	public void shouldIsBadCellBecauseNegatineY() {
		cell = new Cell(2, -1);
		assertTrue(cell.isBad());
	}

	@Test
	public void shouldIsBadCellBecauseYBiggerHeightEnvironment() {
		cell = new Cell(1, 15);
		assertTrue(cell.isBad());
	}

	@Test
	public void shouldIsNotBadCell() {
		cell = new Cell(1, 1);
		assertFalse(cell.isBad());
	}

	@Test
	public void shouldEqualsCells() {
		cell = new Cell(1, 2);
		newCell = new Cell(1, 2);
		assertTrue(cell.equals(newCell));
	}

	@Test
	public void shouldNotEqualsCells() {
		cell = new Cell(1, 1);
		newCell = new Cell(2, 2);
		assertFalse(cell.equals(newCell));
	}

	@Test
	public void testCellToString() {
		cell = new Cell(2, 4);
		String expected = "[2,4]";
		assertEquals(expected, cell.toString());
	}

}
